package com.swfgui.utils
{
	import flash.net.registerClassAlias;
	import flash.utils.ByteArray;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;

	public class ClassUtil
	{
		public static function clone( value:* ):*
		{
			var s : String = getQualifiedClassName( value ).replace("::",".");
			registerClassAlias( s , Class( getDefinitionByName( s ) ) );
			var ba : ByteArray = new ByteArray();
			ba.writeObject( value );
			ba.position = 0;
			var r : * = ba.readObject();
			return r;
		}
		
		/**
		 * 返回类名，不包括包名称，例如flash.utils::ByteArray，则返回ByteArray
		 * @param value
		 * @return 
		 */
		public static function getClassName(value:*):String
		{
			var fullName:String = getQualifiedClassName(value);
			var name:String;
			if(fullName.indexOf("::") != -1)
			{
				name = fullName.substr(fullName.indexOf("::") + 2);
			}
			else
			{
				name = fullName;
			}
			
			return name;
		}
	}
}